package com.situ.mybatis.test;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.situ.mybatis.entity.Student;
import com.situ.mybatis.mapper.IStudentDao;
import com.situ.mybatis.mapper.IUserDao;
import com.situ.mybatis.util.MyBatisUtil;

public class MyBatisTest2 {
	
	@Test
	public void test1() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
		Student student = new Student();
		student.setName("zhangsan");
		//student.setAge(34);
		List<Student> list = studentDao.search(student);
		for (Student stu : list) {
			System.out.println(stu);
		}
	}
	
	@Test
	public void test2() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
		Student student = new Student();
		student.setId(33);
		//student.setName("superadmin111");
		student.setAge(99);
		student.setGender("");
		int count = studentDao.update(student);
		sqlSession.commit();
		System.out.println(count);
	}
	
	@Test
	public void testSelectByIdArray() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
		int[] idArray = {10,11,12,13};
		List<Student> list = studentDao.selectByIdArray(idArray);
		for (Student student : list) {
			System.out.println(student);
		}
	}
	@Test 
	public void testSelectByIdList() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
		List<Integer> idList = new ArrayList<Integer>();
		idList.add(10);
		idList.add(11);
		idList.add(12);
		List<Student> list = studentDao.selectByIdList(idList);
		for (Student student : list) {
			System.out.println(student);
		}
	}
	
	@Test
	public void testSearchByCondition() {
		SqlSession sqlSession = MyBatisUtil.getSqlSession();
		IStudentDao studentDao = sqlSession.getMapper(IStudentDao.class);
		Student student = new Student();
		student.setAge(23);
		List<Student> list = studentDao.searchByCondition(student);
		for (Student student2 : list) {
			System.out.println(student2);
		}
	}
}
